<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <textarea></textarea>
        <p>您已经输入了0个字</p>
        <script>
            //获取元素
            let textarea = document.querySelector("textarea");
            let p = document.querySelector("p");
            //使用⚠️oninput获取，这个属性为检测实时输入的值
            textarea.oninput = (event) => {
                //用event的方法进行获取值
                let textareaValue = event.target.value;
                let length = textareaValue.length;
                //这里使用``方便进行传值
                let a = `您已经输入了${length}个字`;
                //输出在p的标签里
                p.innerHTML = a;
            };
        </script>
    </body>
</html>
